package com.outsider.note.task;

import java.util.Date;

import org.apache.log4j.Logger;

import com.jfinal.kit.PropKit;
import com.jfinal.weixin.sdk.api.AccessTokenApi;
import com.jfinal.weixin.sdk.api.ApiConfigKit;
import com.jfinal.weixin.sdk.api.ApiResult;
import com.jfinal.weixin.sdk.api.CustomServiceApi;
import com.outsider.note.dao.TextNote;
import com.outsider.note.entity.BaseNote;
import com.outsider.weixin.dao.User;

public class TextNoteTimerTask extends NoteTimerTask{
	public TextNoteTimerTask(BaseNote note) {
		super(note);
	}

	public void run() {
		TextNote textNote=(TextNote)note;
		String openID=User.dao.findById(textNote.getUserId()).getOpenId();
		String str="您有一条Note:"+TextNote.dao.findById(note.getID()).getMSG();
		ApiResult result=null;
		do{
			Logger.getLogger("").info("Use Access Token "+AccessTokenApi.getAccessTokenStr());
			result=CustomServiceApi.sendText(openID, str);
		}
		while (result.isAccessTokenInvalid());

		Logger.getLogger("").info("Send Text Note ID:"+textNote.getID()+" Success");
		
	}

	@Override
	public Date getCallDate() {
		return note.getDATE();
	}
}
